<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Reviews_report extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_review_model','admin_member_model','admin_listing_model','admin_counter_model'));
		
		$this->load->library('pagination');
		//$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}

	function index()
	{

		//-- Default Value --//
		$status=51;
		$featured=false;
		$search = "";

		if($this->input->post('order')){
			$order = $this->input->post('order');

			switch ($order) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
				case 'featured':
					$status = 51;
					$featured=true;
					break;
			}
		}

		$offset = 0 + $this->uri->segment(5);
		
		$total = $this->admin_counter_model->count_all_reviews('review_master');

		//print "$total";
		//die();

		$perpage = 5;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';


		$config['base_url'] = base_url() . 'secure/reports/reviews_report/index/';
		
		$cur =base_url()."secure/reports/reviews_report/index/";
		$cur = '<a href="'. $cur   .'">&laquo; First</a>';
		$config['full_tag_open'] = '<div class="pagination"><ul>';
		$config['full_tag_close'] = '</ul></div><!--pagination-->';
		$config['first_link'] = '&laquo; First';
		$config['first_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = 'Last &raquo;';
		$config['last_tag_open'] = '<li class="next page" style="display:inline">';
		$config['last_tag_close'] = '</li>';
		$config['next_link'] = 'Next &rarr;';
		$config['next_tag_open'] = '<li class="next page" style="display:inline">';
		$config['next_tag_close'] = '</li>';
		$config['prev_link'] = '&larr; Previous';
		$config['prev_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['prev_tag_close'] = '</li>';
		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';
		$config['num_tag_open'] = '<li class="page">';
		$config['num_tag_close'] = '</li>';
		$config['display_pages'] = FALSE;

		if($status==51)
		{
			$data['review']['all'] = $this->admin_review_model->get_reviews($featured = $featured, $status = $status, $perpage, $offset);
				
				
			$this->pagination->initialize($config);
		}else{

			$status=1;
			$offset = 0 + $this->uri->segment(5);
			
			$total = $this->admin_counter_model->count_inactive_reviews($status);

			//print "$total";
			//die();

			$perpage = 5;
			$config['per_page'] = $perpage;
			$config['total_rows'] = $total;
			$config['uri_segment'] = '5';

			$config['base_url'] = base_url() . 'secure/reports/reviews_report/inactive/';
			
			$cur =base_url()."secure/reports/reviews_report/inactive/";
			$cur = '<a href="'. $cur   .'">&laquo; First</a>';
			$config['full_tag_open'] = '<div class="pagination"><ul>';
			$config['full_tag_close'] = '</ul></div><!--pagination-->';
			$config['first_link'] = '&laquo; First';
			$config['first_tag_open'] = '<li class="prev page" style="display:inline">';
			$config['first_tag_close'] = '</li>';
			$config['last_link'] = 'Last &raquo;';
			$config['last_tag_open'] = '<li class="next page" style="display:inline">';
			$config['last_tag_close'] = '</li>';
			$config['next_link'] = 'Next &rarr;';
			$config['next_tag_open'] = '<li class="next page" style="display:inline">';
			$config['next_tag_close'] = '</li>';
			$config['prev_link'] = '&larr; Previous';
			$config['prev_tag_open'] = '<li class="prev page" style="display:inline">';
			$config['prev_tag_close'] = '</li>';
			$config['cur_tag_open'] = '<li class="active"><a href="">';
			$config['cur_tag_close'] = '</a></li>';
			$config['num_tag_open'] = '<li class="page">';
			$config['num_tag_close'] = '</li>';
			$config['display_pages'] = FALSE;
			
			$data['review']['all'] = $this->admin_review_model->get_inactive_reviews($featured = $featured, $status = $status, $perpage, $offset);
				
			$this->pagination->initialize($config);
		}

		//$data['review']['all'] = $this->admin_review_model->get_reviews($featured = false, $status = $status, $no = 30, $offset = NULL);

		if($this->input->post('search')){
			$search = 	trim($this->input->post('search'));
			$data['review']['all'] = $this->admin_review_model->search($search = $search);
			//print $search;
		}

		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/reviews_report',$data);
	}

	
	function inactive()
	{
	
		//-- Default Value --//
		$status=1;
		$featured=false;
		$search = "";
	
		if($this->input->post('filter')){
			$filter = $this->input->post('filter');
	
			switch ($filter) {
				case 'active':
					$status = 51;
					break;
				case 'inactive':
					$status = 1;
					break;
				case 'featured':
					$status = 51;
					$featured=true;
					break;
			}
		}
	
		$status=1;
		$offset = 0 + $this->uri->segment(5);
		
		$total = $this->admin_counter_model->count_inactive_reviews($status);
	
		//print "$total";
		//die();
	
		$perpage = 5;
		$config['per_page'] = $perpage;
		$config['total_rows'] = $total;
		$config['uri_segment'] = '5';
	
		
		$config['base_url'] = base_url() . 'secure/reports/reviews_report/inactive/';
		
		$cur =base_url()."secure/reports/reviews_report/inactive/";
		$cur = '<a href="'. $cur   .'">&laquo; First</a>';
		$config['full_tag_open'] = '<div class="pagination"><ul>';
		$config['full_tag_close'] = '</ul></div><!--pagination-->';
		$config['first_link'] = '&laquo; First';
		$config['first_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = 'Last &raquo;';
		$config['last_tag_open'] = '<li class="next page" style="display:inline">';
		$config['last_tag_close'] = '</li>';
		$config['next_link'] = 'Next &rarr;';
		$config['next_tag_open'] = '<li class="next page" style="display:inline">';
		$config['next_tag_close'] = '</li>';
		$config['prev_link'] = '&larr; Previous';
		$config['prev_tag_open'] = '<li class="prev page" style="display:inline">';
		$config['prev_tag_close'] = '</li>';
		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';
		$config['num_tag_open'] = '<li class="page">';
		$config['num_tag_close'] = '</li>';
		$config['display_pages'] = FALSE;
		
		$data['review']['all'] = $this->admin_review_model->get_inactive_reviews($featured = $featured, $status = $status, $perpage, $offset);
			
		$this->pagination->initialize($config);
	
		if($this->input->post('search')){
			$search = 	trim($this->input->post('search'));
			$data['review']['all'] = $this->admin_review_model->search($search = $search);
			//print $search;
		}
	
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('reports/reviews_report',$data);
	}
	
	function action()
	{
		$status=NULL;
		$id=NULL;

		if($this->input->post('action')){
			$action = $this->input->post('action');
			$id = $this->input->post('reviews_id');

			switch ($action) {
				case 'active':
					$status = 51;
						
					$this->admin_review_model->change_status($status,$id);
						
					break;
				case 'inactive':
					$status = 1;
					$this->admin_review_model->change_status($status,$id);
					break;
				case 'delete':

					$this->admin_review_model->delete($id);
					break;

						
				case 'edit':
						
					$url= 'secure/approval/reviews/edit/'.$id;
					redirect($url);
					break;
						
			}
		}

		redirect('secure/reports/reviews_report');
	}


	function change_reviews_status($status=NULL,$id=NULL){
		$this->admin_review_model->change_status($id,$status);
		redirect('secure/reports/reviews_report');
	}

	function delete_reviews($id){
		$this->admin_review_model->delete($id);
		redirect('secure/reports/reviews_report');
	}
}











